package com.datatraffic.salesup;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.datatraffic.salesup.model.Task;

public class ListAdapterTasks extends ArrayAdapter<Task>{

    Context context; 
    int layoutResourceId; 
    Task data[] = null;
    
    public ListAdapterTasks(Context context, int layoutResourceId, Task[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ItemHolder holder = null;
        
        if(row == null)
        {//Activity
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new ItemHolder();
            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitulo);
            holder.txtDescripcion = (TextView)row.findViewById(R.id.textViewComentario);
            
            row.setTag(holder);
        }
        else
        {
            holder = (ItemHolder)row.getTag();
        }
        
        Task item = data[position];
        holder.txtTitle.setText(item.getTarea());
        holder.txtDescripcion.setText(item.getDescripcion());
        
        
        return row;
    }
    
    public void setData(Task[] data)
    {
    	this.data=data;
    }
    
    
    @Override
    public void clear()
    {
    	data=new Task[]
		        {
	            
	        };
    }
    
    
    static class ItemHolder
    {
        TextView txtTitle;
        TextView txtDescripcion;
    }
}